home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapradial.py < prev    next >
Text File  |  2004-01-05  |  4KB  |  144 lines

  1. # QuArK  -  Quake Army Knife
  2. #
  3. # Copyright (C) 2001 The Quark Community
  4. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  5. # FOUND IN FILE "COPYING.TXT"
  6. #
  7. #$Header: /cvsroot/quark/runtime/plugins/mapradial.py,v 1.5 2001/08/15 17:52:01 decker_dk Exp $
  8.  
  9. Info = {
  10.    "plug-in":       "Radial Duplicator",
  11.    "desc":          "Replicate objects around an axis",
  12.    "date":          "03 Mar 2001",
  13.    "author":        "tiglari",
  14.    "author e-mail": "tiglari@hexenworld.com",
  15.    "quark":         "Quark 6.2" }
  16.  
  17.  
  18. from quarkpy.maputils import *
  19. from quarkpy.qdictionnary import Strings
  20. import quarkpy.qhandles
  21. import quarkpy.mapduplicator
  22. import quarkpy.maphandles
  23. StandardDuplicator = quarkpy.mapduplicator.StandardDuplicator
  24. DuplicatorManager = quarkpy.mapduplicator.DuplicatorManager
  25. from quarkpy.maphandles import MapRotateHandle
  26.  
  27.  
  28. class AxisHandle(MapRotateHandle):
  29.   "a rotating handle that controls a normalized vector spec"
  30.  
  31.   def __init__(self, center, dup, spec, scale1):
  32.       axis = quarkx.vect(dup[spec])
  33.       MapRotateHandle.__init__(self, center, axis, scale1, quarkpy.qhandles.mapicons[11])
  34.       self.dup = dup
  35.       self.spec = spec
  36.  
  37.   def dragop(self, flags, av):
  38.         new = None
  39.         if av is not None:
  40.             new = self.dup.copy()
  41.             new[self.spec] = av.tuple
  42.         return [self.dup], [new], av
  43.  
  44. def macro_dup_radial_align(self, index=0):
  45.     editor=mapeditor()
  46.     if editor is None:
  47.         return
  48.     sel = editor.layout.explorer.sellist
  49.     #  if len(sel)!=1: return
  50.     dup = sel[0]
  51.     undo = quarkx.action()
  52.     if index==1:
  53.         undo.setspec(dup,"axis",'1 0 0')
  54.     elif index==2:
  55.         undo.setspec(dup,"axis",'0 1 0')
  56.     else:
  57.         undo.setspec(dup,"axis",'0 0 1')
  58.     editor.ok(undo, "move axis")
  59.     editor.invalidateviews()
  60.  
  61. quarkpy.qmacro.MACRO_dup_radial_align = macro_dup_radial_align
  62.  
  63. class RadialDuplicator(StandardDuplicator):
  64.     "Radial Duplicator."
  65.  
  66.     def handles(self, editor, view):
  67.         scale = view.scale()
  68.         dup = self.dup
  69.         org = dup.origin
  70.         h = [AxisHandle(org, dup, "axis", scale)]
  71.         return h + DuplicatorManager.handles(self, editor, view)
  72.  
  73.  
  74.     def buildimages(self, singleimage=None):
  75.         if singleimage is not None and singleimage>0:
  76.             return []
  77.         axis = quarkx.vect(self.dup["axis"]).normalized
  78.         around, = self.dup["around"]
  79.         spiral = self.dup["spiral"]
  80.         if spiral is not None:
  81.             upward, outward = spiral
  82.         else:
  83.             upward, outward = 0, 0
  84.         origin = self.dup.origin
  85.         list = self.sourcelist()
  86.         templateorigin = quarkpy.maphandles.GetUserCenter(list)
  87.         #
  88.         # Axis can be tilted
  89.         #
  90.         tiltmat = matrix_rot_u2v(quarkx.vect(0,0,1),axis)
  91.         result = []
  92.         try:
  93.             count = int(self.dup["count"])
  94.         except:
  95.             count = 1
  96.         #
  97.         # A linear matrix can apply cumulatively to the images
  98.         #
  99. #        dupmat = buildLinearMatrix(self.dup)
  100.  
  101.         if self.dup["linear"] is not None:
  102.             dupmat = self.dup["linear"]
  103.         else:
  104.            dupmat = '1 0 0 0 1 0 0 0 1'
  105.         dupmat = quarkx.matrix(dupmat)
  106.         cummat = quarkx.matrix('1 0 0 0 1 0 0 0 1')
  107.         try:
  108.             for i in range(0, count):
  109.                 group=quarkx.newobj('radial %d:g'%i)
  110.                 for item in list:
  111.                     group.appenditem(item.copy())
  112.                 result.append(group)
  113.                 group.linear(templateorigin,cummat)
  114.                 cummat = dupmat*cummat
  115.                 angle = i*around*deg2rad
  116.                 matrix = tiltmat*matrix_rot_z(angle)
  117.                 shift = upward*axis*i
  118.                 group.linear(origin,matrix)
  119.                 group.translate(shift)
  120.                 center=quarkpy.maphandles.GetUserCenter(group)
  121.                 radvec = perptonormthru(origin,center,axis).normalized
  122.                 radvec = matrix*radvec
  123.                 shift = -i*outward*radvec
  124.                 group.translate(shift)
  125.         except:
  126.             # Catch math-computation errors and return nothing if so
  127.             result = []
  128.  
  129.         return result
  130.  
  131. #
  132. # Register the duplicator type from this plug-in.
  133. #
  134.  
  135. quarkpy.mapduplicator.DupCodes.update({
  136.   "dup radial":     RadialDuplicator,
  137. })
  138.  
  139. # ----------- REVISION HISTORY ------------
  140. #$Log: mapradial.py,v $
  141. #Revision 1.5  2001/08/15 17:52:01  decker_dk
  142. #Exception-catch for math-computation errors
  143. #
  144.